<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../css/reset.css">
    <style>
        .box {
            width: 200px;
            height: 200px;
            background-color: grey;
            margin: 50px;
            overflow: hidden;
        }

        .sub {
            width: 100px;
            height: 100px;
            background-color: #6ff;
            margin: 50px;
        }
    </style>
</head>

<body>
    <div class="box">
        <div class="sub"></div>
    </div>
</body>
<script>

    // 鼠标相关的事件
    // onclick    当鼠标左键单击时触发 (按下并松开)
    // ondblclick 当鼠标左键双击时触发 (按下并松开 -> 短时间内)

    // onmousedown  当鼠标按键被按下时触发
    // onmouseup    当鼠标按键被松开时触发
    // onmousemove    当鼠标移动时触发
    // onmousewheel    当鼠标滚轮滚动时触发

    // onmouseover  鼠标移入时触发
    // onmouseout  鼠标移出时触发

    // 问题: 
    // 给父元素绑定 onmouseover,onmouseout -> 当从父元素移动到子元素时 子元素会先触发移出,在触发移入

    // 解决方法:  使用onmouseenter,onmouseleave 替代  onmouseover,onmouseout 

    var box = document.querySelector(".box");

    // box.onmouseover = function () {
    //     console.log("鼠标移入/滑过");
    // }
    // box.onmouseout = function () {
    //     console.log("鼠标移出");
    // }


    box.onmouseenter = function () {
        console.log("鼠标移入/滑过");
    }
    box.onmouseleave = function () {
        console.log("鼠标移出");
    }







</script>

</html>